﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectTest.Models
{
    public class QLGiangDay
    {
        private DBTestDataContext db = new DBTestDataContext();
      
        //Create
        public void Create(GiangDay gd)
        {
            try
            {
                db.GiangDays.InsertOnSubmit(gd);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
        //Edit
        public void Edit(GiangDay gdEdited, int mgd)
        {
            GiangDay gd = db.GiangDays.SingleOrDefault(p => p.MaGD == mgd);
            try
            {
                UpdateInfo(gd, gdEdited);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void UpdateInfo(GiangDay gd, GiangDay gdEdited)
        {
            gd.HocKy = gdEdited.HocKy;
            gd.NamHoc = gdEdited.NamHoc;
            gd.MaGV = gdEdited.MaGV;
            gd.MaHP = gd.MaHP;
        }
        //Delete
        public void Delete(int mgd)
        {
            GiangDay gd = db.GiangDays.SingleOrDefault(p =>p.MaGD==mgd);
            try
            {
                db.GiangDays.DeleteOnSubmit(gd);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}